var PageHelper = (() => {
    var body = document.body,
        clientHeight = document.documentElement.clientHeight,
        start, during;

    return {
        canScroll: true,
        next: next,
        prev: prev
    };
    function getPage() {
        start = body.scrollTop;
        return start / clientHeight;
    }
    function next() {
        if (start > 0) {
            during = (getPage() + 1) * clientHeight;
            window.requestAnimationFrame(update);
            console.log('next', start, during);
        }
    }
    function prev() {
        if (start) {
            during = (getPage() - 1) * clientHeight;
            window.requestAnimationFrame(update);
            console.log('prev', start, during);
        }
    }


    function update(timestamp) {
        // console.log(timestamp);
        if (body.scrollTop < during) {
            body.scrollTop++;
            requestAnimationFrame(update);
        } else if (body.scrollTop > during) {
            body.scrollTop--;
            window.requestAnimationFrame(update);
        } else {
            console.log('end');
            PageHelper.canScroll = true;
        }
        // PageHelper.canScroll = true;
    }
})();



module.exports = function () {
    document.addEventListener('mousewheel', function (e) {

        e.preventDefault();


        if (e.deltaY > 0) {
            console.log('up');
        }
        if (e.deltaY < 0) {
            console.log('bottom');
        }


        // if (PageHelper.canScroll) {
        //     PageHelper.canScroll = false;
        //     if (e.deltaY > 0) {
        //         PageHelper.next();
        //     } else {
        //         PageHelper.prev();
        //     }
        // } else {
        //     e.preventDefault();
        // }

        // console.log(e, e.deltaY);
    });
}   